# MVP1 测试脚本 - PowerShell 版本

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "     MVP1 客户质量评分系统 - 完整测试" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""

# 检查是否在正确的目录
if (-not (Test-Path ".\venv")) {
    Write-Host "❌ 错误: 未找到 venv 目录" -ForegroundColor Red
    Write-Host "   请确保在项目根目录 (d:\n8ncrm) 执行此脚本" -ForegroundColor Yellow
    exit 1
}

Write-Host "Step 1: 检查 Python 环境..." -ForegroundColor Yellow
$pythonPath = ".\venv\Scripts\python.exe"

if (-not (Test-Path $pythonPath)) {
    Write-Host "❌ 错误: 未找到 Python 虚拟环境" -ForegroundColor Red
    Write-Host "   路径: $pythonPath" -ForegroundColor Yellow
    exit 1
}

& $pythonPath --version
Write-Host "✅ Python 环境正常" -ForegroundColor Green
Write-Host ""

Write-Host "Step 2: 检查后端导入..." -ForegroundColor Yellow
& $pythonPath check_backend_imports.py
Write-Host ""

Write-Host "Step 3: 执行数据库迁移..." -ForegroundColor Yellow
& $pythonPath backend\apply_quality_migration.py
Write-Host ""

Write-Host "Step 4: 检查后端服务器状态..." -ForegroundColor Yellow
$response = $null
try {
    $response = Invoke-WebRequest -Uri "http://localhost:8000/docs" -TimeoutSec 2 -ErrorAction SilentlyContinue
    if ($response.StatusCode -eq 200) {
        Write-Host "✅ 后端服务器正在运行: http://localhost:8000" -ForegroundColor Green
        Write-Host "   API 文档: http://localhost:8000/docs" -ForegroundColor Cyan
    }
} catch {
    Write-Host "⚠️  后端服务器未运行" -ForegroundColor Yellow
    Write-Host "   启动命令: cd backend; python smart_start.py" -ForegroundColor Cyan
}
Write-Host ""

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "测试完成！" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "下一步操作:" -ForegroundColor Yellow
Write-Host "1. 如果后端未运行，执行: cd backend; python smart_start.py" -ForegroundColor White
Write-Host "2. 访问 API 文档: http://localhost:8000/docs" -ForegroundColor White
Write-Host "3. 访问测试页面: file:///d:/n8ncrm/test_mvp1_api.html" -ForegroundColor White
Write-Host "4. 访问 Dashboard: http://localhost:3000/dashboard" -ForegroundColor White
Write-Host ""
